<?php   // $Id: pre_convert.php 280 2008-08-15 16:53:15Z pcoustillas $ ?>
<?php

/*Copyright (C) 2003-2004 Guy Hendrickx
Licensed under the terms of the GNU  General Public License:http://www.opensource.org/licenses/gpl-license.php
File Authors:Guy Hendrickx
Modification : Pierre Coustillas*/

$type_verif="devis"; //pour vérifier que l'utisateur à le droit de valider ce devis
$num_doc=$_GET['num_dev']; //pour vérifier que l'utisateur à le droit de valider ce devis
require_once(dirname(__FILE__) ."/verif_client.php");
require_once(dirname(__FILE__) ."/../include/config/common.php");
require_once(dirname(__FILE__) ."/../include/language/$lang.php");
require_once(dirname(__FILE__) ."/../include/config/var.php");
require_once(dirname(__FILE__) ."/../include/utils.php");

$conf_xml=simplexml_load_file(dirname(__FILE__) . '/../include/config.xml');
$theme=$conf_xml->generale->theme;

	$num_dev=isset($_GET['num_dev'])?$_GET['num_dev']:"";
	$login=isset($_GET['login'])?$_GET['login']:"";
	// require_once("head.php");
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
  <head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>Connection à OpenDCF</title>
	<link rel="stylesheet" type="text/css" href="../include/themes/<?php echo "$theme";?>/style.css" />
	<link rel="shortcut icon" type="image/x-icon" href="../image/favicon.ico" />

</head>

<body>

<?php
$sql2 = "SELECT ${tblpref}cont_dev.num, uni, quanti, article, tot_art_htva FROM ${tblpref}cont_dev RIGHT JOIN
		${tblpref}article on ${tblpref}cont_dev.article_num = ${tblpref}article.num WHERE dev_num=$num_dev";
$result = mysql_query($sql2) or die("Erreur SQL2 !<br/>$sql2<br/>" . mysql_error());

?>

<center>
<br/>
<br/>
<form action="convert_client.php" method="post">
	<table border="0" align="center">
		<caption><?php aff_lang("Détail du devis") ?></caption>
		<tr>
			<th width="150"><?php echo $lang_quantite ;?></th>
			<th width="150"><?php echo $lang_unite ;?></th>
			<th width="150"><?php echo $lang_article ;?></th>
			<th width="150"><?php echo $lang_montant_htva ;?></th>
		</tr>

		<?php
		while($data = mysql_fetch_array($result))
		{
			$quanti = $data['quanti'];
			$uni = $data['uni'];
			$article = $data['article'];
			$tot = $data['tot_art_htva'];
			$num_cont = $data['num'];
			?>
		<tr>
			<td class='<?php echo couleur_alternee (TRUE); ?>' style="text-align:right"><?php echo $quanti ?></td>
			<td class='<?php echo couleur_alternee (FALSE); ?>'><?php echo $uni  ?></td>
			<td class='<?php echo couleur_alternee (FALSE); ?>'><?php echo $article ?></td>
			<td class='<?php echo couleur_alternee (FALSE); ?>' style="text-align:right"><?php echo "$tot $devise" ?></td>
		</tr>
		<?php
		}
	
		//on calcule la somme des contenus du bon
		$sql = " SELECT SUM(tot_art_htva) FROM ${tblpref}cont_dev WHERE dev_num=$num_dev";
		$result = mysql_query($sql) or die("Erreur calcul sum HT !<br/>$sql<br/>" . mysql_error());
		$total_bon = mysql_result($result,0);
	
		//on calcule la some de la tva des contenus du bon
		$sql = " SELECT SUM(to_tva_art) FROM ${tblpref}cont_dev WHERE dev_num=$num_dev";
		$result = mysql_query($sql) or die("Erreur SQL !<br/>$sql<br/>" . mysql_error());
		$total_tva = mysql_result($result,0);
		?>
		<tr>
			<td colspan="4"><hr/></td>
		</tr>

		<tr>
			<td colspan="2"></td>
			<td class='totalmontant'><?php echo "$lang_total" ?></td>
			<td class='totalmontant'><?php echo montant_financier($total_bon) ?></td>
		</tr>
		<tr>
			<td colspan="2"></td>
			<td class='totalmontant'><?php echo "$lang_tva" ?></td>
			<td class='totalmontant'><?php echo montant_financier($total_tva) ?></td>
		</tr>
		<tr>
			<td colspan="2"></td>
			<td class='totalmontant'><?php aff_lang("Total ttc") ?></td>
			<td class='totalmontant'><?php echo montant_financier($total_bon + $total_tva) ?></td>
		</tr>

		<tr>
			<td colspan="4">&nbsp;</td>
		</tr>
		<tr>
			<td class="grand" colspan="2" style="vertical-align:middle;text-align:center">
				<?php aff_lang("Merci d'ajouter un message de confirmation") ?>
			</td>
			<td class="texte0" colspan="2"><textarea rows="10" cols="40" name="message"></textarea></td>
		</tr>
		<tr>
			<td colspan="3">
				<center>
					<input type="hidden" name="login" value ='<?php echo "$login" ?>' />
					<input type="hidden" name="num_dev" value ='<?php echo "$num_dev" ?>' />
					<input type="submit" value="      <?php aff_lang("Accepter le devis") ?>      " />
				</center>
			</td>
			<td>
				<center>
					<input type="reset" value="<?php echo $lang_annuler; ?>" />
				</center>
			</td>
		</tr>
  </table>
</form>
</center>

</body>


</html>

